// pagesEnterprise/pages/parkManage/parkManage.js
import ajax from "../../../utils/index"
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    parkList: [],
    auditParkList: [],
    auditList: [],
    failList: [],
    pageNum: 1,
    reachBottomShow: true,
  },
  //新增 - 企业认证流程
  add: function () {
    wx.navigateTo({
      url: '/pages/home/apply/apply',
    })
  },

  //路由 - 企业管理跳转
  routCompany: function (e) {
    let item = e.currentTarget.dataset.item
    wx.navigateTo({ url: `/pagesEnterprise/pages/parkManage/parkManage?id=${item.gardenId}&cardId=${item.cardId}` })
  },

  //路由 - 修改企业 
  editCompany: function (e) {
    let item = e.currentTarget.dataset.item
    let id = item.applygardenId
    wx.navigateTo({
      url: '/pagesEnterprise/pages/parkInfoDetails/parkInfoDetails?id=' + id
    })
  },
  async getParkUnderReviewList() {
    const res = await ajax.get('/wx/appletMessage/parkUnderReviewList')
    const auditList = res.rows.filter(item => item.audit == 0)
    const failList = res.rows.filter(item => item.audit == 2)
    this.setData({ auditList, failList })
  },
  //查询 - 当前登录人的企业 以及认证状态
  get_park_supervise_list: function () {
    let that = this
    ajax.get('/wx/appletMessage/parkSuperviseList', {
      pageSize: 20,
      pageNum: this.data.pageNum,
    }).then(res => {
      if (res.code == 200) {
        that.setData({
          parkList: [...that.data.parkList, ...res.rows],
        })
        if (res.total <= that.data.pageNum * 10) {
          that.setData({
            reachBottomShow: false
          })
        }
      } else {
        wx.showToast({
          title: res.msg,
          icon: 'none'
        })
      }
    })
  },
  /**
   * 联系客服
   */
  serviceTelEvent() {
    ajax.makePhoneCall(app.globalData.serviceTel)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.get_park_supervise_list()
    this.getParkUnderReviewList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.data.pageNum += 1
    this.get_park_supervise_list()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})